<template>
    <div id='dres-container' class="bi-page bi-bg-grey">
        <div class="bi-toolbar bi-bg-white">
            <el-row>
                <!-- 上移 -->
                <el-button v-show="isShowMove"
                           size="mini"
                           class="bi-el-btn bi-el-btn-first"
                           :disabled="isInMyWorkSpace ||btnStates[13]"
                           @click="moveUp">
                    上移
                </el-button>
                <!-- 下移 -->
                <el-button v-show="isShowMove"
                           size="mini"
                           class="bi-el-btn"
                           :disabled="isInMyWorkSpace ||btnStates[14]"
                           @click="moveDown">
                    下移
                </el-button>
                <!-- 新建应用系统 -->
                <el-button size="mini"
                           class="bi-el-btn bi-el-btn-first"
                           :disabled="isInMyWorkSpace ||btnStates[0]"
                           @click="newDomain">
                    新建应用系统
                </el-button>
                <!-- 编辑应用系统 -->
                <!--<el-button :disabled="btnStates[1]">编辑应用系统-->
                <!--</el-button>-->
                <!-- 删除应用系统 -->
                <el-button size="mini"
                           class="bi-el-btn"
                           :disabled="isInMyWorkSpace ||btnStates[2]"
                           @click="deleteDomain">
                    删除应用系统
                </el-button>
                <!-- 新建目录 -->
                <el-button size="mini"
                           class="bi-el-btn"
                           :disabled="btnStates[3]"
                           @click="newFolder" >
                    新建目录
                </el-button>
                <!-- 编辑目录 -->
                <!--<el-button :disabled="btnStates[4]">编辑目录-->
                <!--</el-button>-->
                <!-- 删除目录 -->
                <el-button size="mini"
                           class="bi-el-btn"
                           :disabled="btnStates[5]"
                           @click="deleteFolder" >
                    删除目录
                </el-button>
                <!-- 刷新目录 -->
                <el-button size="mini"
                           class="bi-el-btn"
                           :disabled="btnStates[6]"
                           @click="refreshFolder" >
                    刷新目录
                </el-button>
                <!-- 新建资源 -->
                <el-button size="mini"
                           class="bi-el-btn"
                           :disabled="btnStates[7]"
                           @click="newDres" >
                    新建数据资源
                </el-button>
                <!-- 删除资源 -->
                <el-button size="mini"
                           class="bi-el-btn"
                           :disabled="btnStates[8]"
                           @click="deleteDres" >
                    删除数据资源
                </el-button>
                <!-- 发布资源 -->
                <el-button v-show="isPublished"
                           size="mini"
                           class="bi-el-btn"
                           :disabled="btnStates[9]"
                           @click="publishRes">
                    {{ publishBtnTitle }}
                </el-button>
                <!-- 取消发布 -->
                <el-button v-show="isPublished"
                           size="mini"
                           class="bi-el-btn"
                           :disabled="btnStates[10]"
                           @click="revokePublishRes">
                    {{ publishReverseBtnTitle }}
                </el-button>
                <!-- 导入资源 -->
                <el-dropdown size="small" placement="bottom-start" :disabled="btnStates[11]">
                  <el-button class="bi-el-btn" :disabled="btnStates[11]">
                    导入资源
                    <i class="el-icon-arrow-down el-icon--right"></i>
                  </el-button>
                  <el-dropdown-menu slot="dropdown" class="bi-el-btn-dropdown">
                    <el-dropdown-item @click.native="addiresByTableFunc">
                      从数据库导入
                    </el-dropdown-item>
                    <el-dropdown-item @click.native="powerDisgnerFunc">
                      从Power Designer模型导入
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
                <!-- 辅助功能 -->
                <el-dropdown size="small" placement="bottom-start" :disabled="btnStates[12]">
                    <el-button class="bi-el-btn" :disabled="btnStates[12]">
                        辅助功能
                        <i class="el-icon-arrow-down el-icon--right"></i>
                    </el-button>
                    <el-dropdown-menu slot="dropdown" class="bi-el-btn-dropdown">
                        <el-dropdown-item @click.native="updateIndexAll">
                            <v-updateIndexView ref="updateIndexView"></v-updateIndexView>
                            更新全部索引
                        </el-dropdown-item>
                        <el-dropdown-item v-if="isResReportShow"
                                          @click.native="generateResReport">
                            生成资源报告
                        </el-dropdown-item>
                        <el-dropdown-item v-if="!isInMyWorkSpace"
                                          @click.native="modifyAutoEdit">
                            自动编目
                        </el-dropdown-item>
                        <el-dropdown-item @click.native="erManage">
                            ER图管理
                        </el-dropdown-item>
                        <el-dropdown-item v-if="isConformCheckShow"
                                          @click.native="doBatchConformCheck">
                            符合性检测
                        </el-dropdown-item>
                        <el-dropdown-item v-if="isOpenMetaGraph"
                                          :disabled="!isResTreeNode"
                                          @click.native="resBloodMap">
                            血缘分析
                        </el-dropdown-item>
                        <el-dropdown-item v-if="isOpenMetaGraph"
                                          :disabled="!isResTreeNode"
                                          @click.native="resAffectMap">
                            影响分析
                        </el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </el-row>
        </div>
        <div class="bi-panel bi-layout-content">
            <!--左侧树形-->
            <section v-show="isShowLeft" class="bi-panel bi-layout-left bi-bg-white">
                <el-tree
                    ref="folderTree"
                    class="bi-el-tree"
                    node-key="id"
                    :indent=24
                    :props="props"
                    :highlight-current="true"
                    :expand-on-click-node="false"
                    :default-expanded-keys="defExpKeys"
                    :load="queryFolderTree" lazy
                    @node-click="setCurrentTreeNode">
                    <template slot-scope="{ node, data }">
						            <span style="position: relative;">
                            <span v-if="data.relatedWorkSpace"
                                  :class="data.icon + ' bi-ui-iconfont '">
                                <i v-if="!isInMyWorkSpace"
                                    class=" bi-ui-iconfont bi-ui-icon-irp-app-decorate-green workspace-decorate ">
                                </i>
                            </span>
                            <span v-else
                                  :class="data.icon + ' bi-ui-iconfont '">
                            </span>
							              <span :title="getTreeNodeLable(data)">{{ getTreeNodeLable(data) }}</span>
						            </span>
                    </template>
                </el-tree>
            </section>
            <!--中间分隔栏-->
            <section class="bi-layout-spliter">
                <div class="bi-layout-spliter-content">
                    <span class="bi-ui-iconfont bi-ui-icon-spliter"
                          :class="{'bi-ui-icon-spliter-fold': !isShowLeft}"
                          @click="isShowLeft= !isShowLeft">
                    </span>
                </div>
            </section>
            <!--默认展示：空页面-->
            <section v-if="!isShowRight && !isShowER && !isShowFolderModifyPage"
                     class="bi-panel bi-layout-right bi-bg-white"
                     :class="{'bi-layout-right-withoutLeft': !isShowLeft}">
            </section>
            <!--树形节点交互：应用系统、目录-->
            <section v-if="isShowFolderModifyPage&&!isShowER"
                     class="bi-panel bi-layout-right bi-bg-white"
                     :class="{'bi-layout-right-withoutLeft': !isShowLeft}">
                <v-dataResApplicationModifyView v-if="currentTreeNode.type === $folderEnum.application"
                                                ref="dataResApplicationModifyView"
                                                :currNodeId.sync="currentTreeNode.id"
                                                :codeTitleReadOnly="isInMyWorkSpace || currentTreeNode.relatedWorkSpace"
                                                @save="modifyDomain"
                                                @modify="applicationModifyCallback">
                </v-dataResApplicationModifyView>
                <v-dataResFolderModifyView v-if="currentTreeNode.type === $folderEnum.folder"
                                           ref="dataResFolderModifyView"
                                           :category.sync="category"
                                           :currNodeId.sync="currentTreeNode.id"
                                           :parentGuid.sync="currentTreeNode.parent"
                                           @save="saveModifyFolder"
                                           @modify="folderModifyCallback">
                </v-dataResFolderModifyView>
            </section>
            <!--树形节点交互：资源-->
            <section v-if="isShowRight&&!isShowER"
                     class="bi-panel bi-layout-right bi-bg-white"
                     :class="{'bi-layout-right-withoutLeft': !isShowLeft}">
                <div class="tab-btns">
                    <el-button  v-show="canModify && (activeName === 'baseInfo')"
                                class="bi-el-btn bi-el-btn-small bi-el-btn-emphasize"
                                :disabled="isSaveBtnDisabled"
                                @click="saveDataResource">
                        保存
                    </el-button>
                    <el-button v-show="canModify && (activeName === 'structure')"
                               class="bi-el-btn bi-el-btn-small bi-el-btn-emphasize"
                               :disabled="isSaveStructBtnDisabled"
                               @click="saveDataStruct">
                        保存
                    </el-button>
                    <el-tooltip effect="light"
                                content="包括数据元素符合性和物理模型一致性检测"
                                placement="top">
                        <el-button v-if="isShowConformCheck && activeName === 'baseInfo'"
                                   class="bi-el-btn bi-el-btn-small bi-el-btn-hint"
                                   @click="doConformCheck">
                            符合性检测
                        </el-button>
                    </el-tooltip>
                </div>
                <el-tabs type="card"
                         class="bi-el-tab"
                         v-model="activeName"
                         :before-leave="tabBeforeLeave"
                         @tab-click="handleTabClick">
                    <el-tab-pane name="baseInfo"
                                 :label="baseinfoTabTitle">
                        <v-baseinfo ref="baseinfo"
                                    :guid="currentTreeNode.id"
                                    :fGuid="currentTreeNode.parent"
                                    :dGuid="currentTreeNode.dGuid"
                                    :category="category"
                                    :resType.sync="currentTreeNode.resType"
                                    :canModify="canModify"
                                    @modify="baseinfoModified">
                        </v-baseinfo>
                    </el-tab-pane>
                    <el-tab-pane v-if="!isNotShowDatastructTab"
                                 label="数据结构"
                                 name="structure">
                        <v-structure ref="structure"
                                     :canModify="canModify"
                                     :setModifyFlag="structTabModified"
                                     :resetModifyFlag="resetStructTabTitle"
                                     @mcConfirm="mcConfirm"
                                     @mcAbandon="mcAbandon">
                        </v-structure>
                    </el-tab-pane>
                    <el-tab-pane label="数据关系" name="dataLink">
                        <v-datalink ref="datalink" :canModify="canModify"></v-datalink>
                    </el-tab-pane>
                </el-tabs>
            </section>
            <!--ER图-->
            <section v-if="isShowER"
                     class="bi-panel bi-layout-right bi-bg-white"
                     :class="{'bi-layout-right-withoutLeft': !isShowLeft}">
                <v-erView ref="erView"
                          :dGuid="formatDGuid(currentTreeNode)"
                          :resCategory="this.$categoryEnum.dataRes"
                          @clickNode="clickERNode"
                          @quitER="quitER">
                </v-erView>
            </section>
        </div>
    </div>
</template>

<script>
import left from '@/assets/irp/left.png';
import right from '@/assets/irp/right.png';
import datalink from "@/views/datares/DataLink.vue";
import structure from "@/views/datares/Structure.vue";
import baseinfo from "@/views/infores/BaseInfoFrame.vue";
import autoEditView from "@/components/irp/auxiliaryFunctions/AutoEditView.vue";
import addresByTableView from "@/components/irp/auxiliaryFunctions/AddresByTableView.vue";
import updateIndexView from "@/components/irp/auxiliaryFunctions/UpdateIndexView.vue";
import powerDisgnerImportview from "@/components/irp/auxiliaryFunctions/PowerDisgnerImport.vue";
import erView from "@/components/irp/erView.vue";
import ConformCheckResultView from "@/components/irp/dialog/ConformCheckResultView.vue";
import generateResReport from "@/components/irp/auxiliaryFunctions/GenerateResReport.vue";
import {dsApi, folderApi, dataresApi, ResAPI, inforesApi, metaGraphApi} from "@/api/irpApi.js";
import {BiCommonApi} from '../../api/irpApi';
import {getWsTitleInSession} from "@/utils/cookies.js";
import DataResApplicationModifyView from "@/views/datares/folder/DataResApplicationModifyView.vue";
import DataResFolderModifyView from "@/views/datares/folder/DataResFolderModifyView.vue";

export default {
    components: {
        "v-baseinfo": baseinfo,
        "v-datalink": datalink,
        "v-structure": structure,
        "v-autoEditView": autoEditView,
        "v-addresByTableView": addresByTableView,
        "v-updateIndexView": updateIndexView,
        "v-powerDisgnerImportview": powerDisgnerImportview,
        "v-erView": erView,
        "v-conformResult": ConformCheckResultView,
        "v-generateResReport": generateResReport,
        "v-dataResApplicationModifyView": DataResApplicationModifyView,
        "v-dataResFolderModifyView": DataResFolderModifyView

    },
    data() {
        return {
            props: {
                label: 'label',
                children: 'children',
                isLeaf: 'isLeaf'
            },
            duration: this.$store.state.duration,	// 提示消息显示时间
            category: this.$categoryEnum.dataRes,	// 资源大类数据资源
            currentTreeNode: null,					// 当前选中树形节点
            isShowRight: false,						// 是否显示右侧区域
            isPublished: false,						// 是否显示发布按钮
            isShowLeft: true,						// 是否显示树形菜单
            activeName: "baseInfo",					// 默认显示页签菜单
            folderTreeRoot: null,					// 目录树形根节点
            publishType: "",						// 发布类型：发布/撤销
            publishDialogTitle: "",					// 发布/撤销窗口标题
            unstructFileResTypes: [],				// 非结构化文件资源列表
            isNotShowDatastructTab: false,			// 是否不显示数据结构页签
            baseinfoModifyFlag: false, 				// 基本属性内容是否已编辑
            structModifyFlag: false,				// 数据结构内容是否已编辑
            baseinfoTabTitle: "基本属性",			// 基本属性页签标题
            nextTabName: null, 						// 切换页签
            nextNodeData: null, 					// 切换节点
            images: {
                left: left,
                right: right
            },
            autoEditVisible: false,					// 辅助功能-相关属性
            centerDialogVisible: false,
            autoEditLforVisible: false,
            progressNum: 0,
            keyPro: null,
            progressMes: "索引执行中。。。",
            closeIsDisabled: true,
            dialogVisible: false,
            addiresByTableVisible: false,
            curentKey: 0,
            powerDesignerVisible: false,
            loading: false,
            isShowER: false,						//显示er图
            canModify: false,
            isShowMove: false,
            isMoveUp: true,
            isMoveDown: true,
            resModifyAuth: true,
            location: null,
            conformResultVisible: false,
            conformResult: {},
            isAdmin: false,
            publishEnable: true,          // 是否启用发布
            publishDisabled: true,					// 是否禁止发布
            publishReverseDisabled: true,			// 是否禁止取消发布
            publishBtnTitle: "发布",
            publishReverseBtnTitle: "取消发布",
            isOpenMetaGraph: false,  //是否开启图谱分析
            defExpKeys: [],     // 默认展开树形节点,
            workSpaces: [], //所有工作空间,
            separatorEnabled: false, // 树形标题是否启用分隔符
            treeNodeSeparator: "", // 树形节点分隔符
            applicationModified: false, //应用系统内容是否编辑
            folderModified: false, //目录内容是否编辑
            doLocateFirstDomain:false
        }
    },
    watch: {
        currentTreeNode: {
            handler(val) {
                this.checkJudge();
            },
            deep: true
        }
    },
    computed: {
        isChange: function () {
            return this.baseinfoModifyFlag
                    ||
                    this.structModifyFlag
                    ||
                    this.applicationModified
                    ||
                    this.folderModified
        },
        isInMyWorkSpace: function () {
            return getWsTitleInSession() !== ''
        },
        btnStates: function () {
            if (this.resModifyAuth) {
                let node = this.currentTreeNode;
                if (node != null) {
                    let nodec = this.$refs.folderTree.getNode(node.id);
                    if (nodec != null && nodec !== 'undefined') {
                        let nodeParent = this.$refs.folderTree.getNode(node.id).parent;
                        if (nodeParent != null && nodeParent !== 'undefined') {
                            let pchildNodes = this.$refs.folderTree.getNode(node.id).parent.childNodes;
                            let index = 0;

                            for (let i = 0; i < pchildNodes.length; i++) {
                                if (pchildNodes[i].data.id === node.id) {
                                    index = i;
                                }
                            }

                            if (pchildNodes.length === 1) {
                                this.isMoveUp = true;
                                this.isMoveDown = true;
                            } else {
                                if (index === 0) {
                                    this.isMoveUp = true;
                                    this.isMoveDown = false;
                                    if (node.type !== pchildNodes[index + 1].data.type) {
                                        this.isMoveDown = true;
                                    }
                                } else if (index === (pchildNodes.length - 1)) {
                                    this.isMoveUp = false;
                                    this.isMoveDown = true;
                                } else {
                                    this.isMoveUp = false;
                                    this.isMoveDown = false;
                                    if (node.type !== pchildNodes[index - 1].data.type) {
                                        this.isMoveUp = true;
                                    } else if (node.type !== pchildNodes[index + 1].data.type) {
                                        this.isMoveDown = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //  未选择任何节点
            if (this.currentTreeNode === null) {
                if (this.resModifyAuth) {
                    return [false, true, true, true, true, true, true, true, true, true, true, true, true, this.isMoveUp, this.isMoveDown];
                } else {
                    return [true, true, true, true, true, true, true, true, true, true, true, true, true, this.isMoveUp, this.isMoveDown];
                }
            }
            // 选中应用节点
            else if (this.currentTreeNode.type === this.$folderEnum.application) {
                if (this.resModifyAuth) {
                    return [false, false, false, false, true, true, false, true, true, false, false, false, false, this.isMoveUp, this.isMoveDown];
                } else {
                    return [true, true, true, true, true, true, false, true, true, true, true, true, true, this.isMoveUp, this.isMoveDown];
                }
            }
            // 选中目录节点
            else if (this.currentTreeNode.type === this.$folderEnum.folder) {
                if (this.resModifyAuth) {
                    return [false, true, true, false, false, false, false, false, true, false, false, false, false, this.isMoveUp, this.isMoveDown];
                } else {
                    return [true, true, true, true, true, true, false, true, true, true, true, true, true, this.isMoveUp, this.isMoveDown];
                }
            }
            // 选中资源节点
            else if (this.currentTreeNode.type === this.$folderEnum.resource) {
                if (this.resModifyAuth) {
                    if (this.publishEnable) {
                        return [false, true, true, true, true, true, true, false, this.publishDisabled, this.publishDisabled, this.publishReverseDisabled, false, false, this.isMoveUp, this.isMoveDown];
                    } else {
                        return [false, true, true, true, true, true, true, false, false, this.publishDisabled, this.publishReverseDisabled, false, false, this.isMoveUp, this.isMoveDown];
                    }
                } else {
                    return [true, true, true, true, true, true, true, !this.resModifyAuth, true, true, true, !this.resModifyAuth, !this.resModifyAuth, this.isMoveUp, this.isMoveDown];
                }
            }
        },
        isResTreeNode: function () {
            return this.currentTreeNode != null && this.currentTreeNode.type === this.$folderEnum.resource
        },
        isSaveBtnDisabled: function () {
            return this.baseinfoModifyFlag === false;
        },
        isShowConformCheck: function () {
            //库表、结构化文件
            return this.currentTreeNode
                    && this.currentTreeNode.type === this.$folderEnum.resource
                    && (this.currentTreeNode.resType.indexOf("table") !== -1 || this.currentTreeNode.resType.indexOf("struct") !== -1);
        },
        isSaveStructBtnDisabled: function () {
            return this.structModifyFlag === false;
        },
        isConformCheckShow: function () {
            if (this.isInMyWorkSpace) {
                return false
            }
            return this.isAdmin
        },
        isResReportShow: function () {
            if (this.isInMyWorkSpace) {
                return false
            }
            return this.isAdmin
        },

        //显示目录或主题域的编辑页面
        isShowFolderModifyPage: function () {
            return this.currentTreeNode != null && this.currentTreeNode.type !== this.$folderEnum.resource
        }
    },
    methods: {
        initTreeNodeSeparator: function () {
            folderApi.queryTreeNodeSeparator().then((result) => {
                this.separatorEnabled = result.enabled
                this.treeNodeSeparator = result.separator
            });
        },
        getTreeNodeLable: function (data) {
            if (this.separatorEnabled) {
                return data.code + this.treeNodeSeparator + data.label
            } else {
                return data.label
            }
        },
        // 嵌入BI后，页面编辑后，提示保存
        initPageModifyListener: function () {
            let $BiTopWin = this.$BiTopWin;

            if ($BiTopWin && $BiTopWin.JQBI && $BiTopWin.JQBI.MC) {
                let $JQBI = this.$BiTopWin.JQBI;

                if ($JQBI) {
                    let that = this;
                    let client = $JQBI.MC.client(window);

                    client.on('beforeselect', function (event, resolve) {
                        if (event.msg.channel === 'MENU' && that.isChange) {
                            let msgContent = "当前资源已修改，是否保存？"
                            if (that.applicationModified) {
                                msgContent = "当前应用系统已修改，是否保存？"
                            }
                            if (that.folderModified) {
                                msgContent = "当前目录已修改，是否保存？"
                            }
                            that.$BiTopWin.$.bi.ui.yesnocancel(msgContent, function () {// 是
                                that.saveDirtyDatas(event, resolve);
                            }, function () {// 否
                                that.clearDirtyFlag();
                                resolve();
                            }, function () {// 取消
                                resolve();
                                event.preventDefault();
                            }, "提示");
                            return;
                        } else {
                            resolve();
                        }
                    });
                    client.open('MENU');
                }
            }
        },
        // 初始化检索定位
        initLocationListener() {
            let that = this;
            if (window.parent.PageContext && window.parent.PageRender) {
                let vp = window.parent.PageRender.getPage('irp_dataresource');
                vp && vp.on('location', function (targetNode) {
                    that.doLocation(targetNode);
                    window.parent.PageContext.cleanLocation();
                });
            }
        },
        // 执行定位
        doLocation: function (targetNode) {
            // 如果是非叶子节点-应用系统/目录
            if (targetNode.isParent === true) {
                let parentId = targetNode.folder.parentGuid;
                let searchId = targetNode.folder.guid;

                this.$nextTick(() => {
                    // 如果是应用系统
                    let folderTree = this.$refs.folderTree;
                    if ((parentId == null) || (parentId === "")) {
                        if (this.folderTreeRoot.loaded) {
                            this.folderTreeRoot.loaded = false;

                            this.folderTreeRoot.expand(() => {
                                folderTree.setCurrentKey(searchId);
                                this.setCurrentTreeNode();
                            });
                        } else {
                            this.folderTreeRoot.expand(() => {
                                folderTree.setCurrentKey(searchId);
                                this.setCurrentTreeNode();
                            });
                        }
                    }
                    // 如果是目录
                    else {
                        // 如果父级目录已经被加载
                        let parentNode = folderTree.getNode(parentId);
                        if (parentNode != null) {
                            if (parentNode.loaded) {
                                parentNode.loaded = false;
                                parentNode.expand(() => {
                                    folderTree.setCurrentKey(searchId);
                                    this.setCurrentTreeNode();
                                });
                            } else {
                                parentNode.expand(() => {
                                    folderTree.setCurrentKey(searchId);
                                    this.setCurrentTreeNode();
                                });
                            }
                        }
                        // 如果父级没有被加载，通过路径递归加载父级
                        else {
                            folderApi.getFolderNodePath({"fGuid": parentId}).then((result) => {
                                if (result.length > 0) {
                                    this.expandByPath(folderTree, searchId, result, 0);
                                }
                            })
                        }
                    }
                });
            }
            // 如果是叶子节点-资源
            else {
                let parentId = targetNode.business.parentId;
                let searchId = targetNode.business.guid;

                this.$nextTick(() => {
                    // 通过搜索定位，父级目录一定为空
                    let folderTree = this.$refs.folderTree;
                    folderApi.getFolderNodePath({"fGuid": parentId}).then((result) => {
                        if (result.length > 0) {
                            this.expandByPath(folderTree, searchId, result, 0);
                        }
                    })
                });
            }
        },
        // 清理修改状态
        clearDirtyFlag: function () {

            if (this.baseinfoModifyFlag) {
                this.resetBaseTabTitle();
            }
            if (this.structModifyFlag) {
                this.resetStructTabTitle();
            }
            if (this.applicationModified) {
                this.applicationModified = false
            }
            if (this.folderModified) {
                this.folderModified = false
            }
        },
        // 保存脏数据
        saveDirtyDatas: function (event, resolve) {
            let that = this;
            if (this.baseinfoModifyFlag) {
                this.$nextTick(() => {
                    this.$refs.baseinfo.saveBaseInfoItem((rstNode) => {
                        if (rstNode === false) {
                            resolve();
                            event.preventDefault();
                        } else {
                            that.resetBaseTabTitle();
                            resolve();
                            that.clearDirtyFlag();
                            return true;
                        }
                    });
                });
            } else if (this.structModifyFlag) {
                this.$nextTick(() => {
                    this.$refs.structure.saveStructureBatch((result) => {
                        if (result === false) {
                            resolve();
                            event.preventDefault();
                        } else {
                            that.resetStructTabTitle();
                            resolve();
                            that.clearDirtyFlag();
                            return true;
                        }
                    });
                });
            } else if (this.applicationModified) {
                this.$nextTick(() => {
                    this.$refs.dataResApplicationModifyView.saveDomain().then((result) => {
                        if (result === false) {
                            resolve();
                            event.preventDefault();
                        } else {
                            resolve();
                            that.clearDirtyFlag();
                            return true;
                        }
                    })
                })
            } else if (this.folderModified) {
                this.$nextTick(() => {
                    this.$refs.dataResFolderModifyView.saveFolder().then((result) => {
                        if (result === false) {
                            resolve();
                            event.preventDefault();
                        } else {
                            resolve();
                            that.clearDirtyFlag();
                            return true;
                        }
                    })
                })
            }
        },
        // 查询全部非结构化文件资源类型
        queryAllUnstructFileResTypes: function () {
            dsApi.queryAllUnstructFileResTypes().then((result) => {
                this.unstructFileResTypes = result;
            });
        },
        // 获取目录树形
        queryFolderTree: function (node, resolve) {
            if (this.folderTreeRoot == null) {
                this.folderTreeRoot = node;
            }

            let datas = {"category": this.category};
            datas.workSpaceTitle = encodeURIComponent(getWsTitleInSession())
            if (node.level > 0) {
                datas.pId = node.data.id;
                datas.pType = node.data.type;
            }
            let firstDomainData = null
            folderApi.queryFolderTree(datas).then((result) => {
                if (!datas.pId) {
                    if (firstDomainData == null && this.doLocateFirstDomain) {
                      firstDomainData = result[0]
                    }

                    for (let i = 0; i < result.length; i++) {
                        let nodeData = result[i];
                        if (this.compareWorkTitle(nodeData.label)) {
                            nodeData.relatedWorkSpace = true;
                            if (this.isInMyWorkSpace) {
                                nodeData.icon = "bi-ui-icon-workspace-folder";
                            } else {
                                nodeData.icon = "bi-ui-icon-irp-app-no-decorate";
                            }
                        }
                    }
                }

                if ((this.folderTreeRoot === node) && (result.length > 0)) {
                    this.defExpKeys.push(result[0].id);
                }
                return resolve(result);

            }).then(() => {
                // 初始定位搜索树形节点
                if (window.parent.PageContext && window.parent.PageContext.getLocation()) {
                    this.location = window.parent.PageContext.getLocation();
                    if ((this.location != null) && (this.location.target != null)) {
                        this.doLocation(this.location.target);
                        window.parent.PageContext.cleanLocation();
                    } else {
                        if (firstDomainData != null) {
                            this.selectFirstDomain(firstDomainData)
                            firstDomainData = null
                            this.doLocateFirstDomain = false
                        }
                    }
                } else {
                    if (firstDomainData != null) {
                        this.selectFirstDomain(firstDomainData)
                        firstDomainData = null
                        this.doLocateFirstDomain = false
                    }
                }
            });
        },
        selectFirstDomain(firstDomainData) {
            this.setCurrentTreeNode(this.$refs.folderTree.getNode(firstDomainData.id).data)
        },
        // 新建应用系统
        newDomain: function () {
            let url = this.$rootUrl + "/biDialog/domainRouter/newDomain"
            let options = {
                id: 'newDomain',
                title: "新建应用系统",
                width: 660,
                height: 500,
                draggable: true,
                ajaxConfirm: true,

                url: url,
                initValue: {
                    isModify: false,
                    category: this.category,
                    folderType: this.$folderEnum.application
                },
                returnValueFunctionName: 'confirmHandle',
                confirmCallback: this.saveNewDomain,
                cancelCallback: this.cancelNewDomain
            }
            this.$BiTopWin.$.bi.ui.frameDialog(options);
        },
        // 保存应用系统
        saveNewDomain: function (newNode) {
            let that = this;
            let folderTree = that.$refs.folderTree;

            if (that.folderTreeRoot.loaded) {
                that.folderTreeRoot.loaded = false;
                that.folderTreeRoot.expand(() => {
                    folderTree.setCurrentKey(newNode.id);
                    that.setCurrentTreeNode();
                });
            } else {
                that.folderTreeRoot.expand(() => {
                    folderTree.setCurrentKey(newNode.id);
                    that.setCurrentTreeNode();
                });
            }
        },
        // 取消保存应用系统
        cancelNewDomain: function () {

        },
        // 编辑应用系统
        modifyDomain: function (res) {
            if (res) {
                this.currentTreeNode.label = res.label;
                this.currentTreeNode.code = res.code;
            }
        },
        // 删除应用系统
        deleteDomain: function () {
            let currNode = this.$refs.folderTree.getCurrentNode();
            if (currNode && currNode.type === this.$folderEnum.application) {
                // 应用系统关联工作空间，禁止删除
                if (this.compareWorkTitle(currNode.label)) {
                    this.$BI.Dialog.warn('已关联工作空间，不允许删除！');
                    return;
                }
            }
            var params = {category: this.category, pId: currNode.id};

            folderApi.queryFolderTree(params).then((res) => {
                if (res.length > 0) {
                    let info = "如删除本应用系统，其下级数据目录及资源也将同步删除。继续删除请输入'OK'并点击确定：";
                    this.$BI.Dialog.warn(info, this.deleteDomainInsure, "确认删除", {ok: true, height: 230});
                } else {
                    this.$BI.Dialog.confirm("确认删除应用系统吗？", () => {
                        this.deleteDomainInsure();
                    });
                }
            });
        },
        // 确认删除应用系统
        deleteDomainInsure: function () {
            let currNode = this.$refs.folderTree.getCurrentNode();
            let datas = {"guid": currNode.id, "type": currNode.type}

            const loadingDomain = this.$loading({
                lock: true,
                text: '正在删除',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            folderApi.deleteFolderItem(datas).then((result) => {
                if (result.deleteSuccess === "true") {
                    loadingDomain.close();
                    let folderTree = this.$refs.folderTree;
                    folderTree.remove(currNode);
                    this.currentTreeNode = null;
                } else if (result.deleteSuccess === "false") {
                    loadingDomain.close();
                    // 元数据依赖项检测
                    top.$.bi.ui.error(result.msg, result.errorDetail);
                }
            }).catch((error) => {
                loadingDomain.close();
            });
        },
        // 新建目录
        newFolder: function () {
            let url = this.$rootUrl + "/biDialog/resFolderRouter/newFolder"
            let currNode = this.$refs.folderTree.getCurrentNode();

            let options = {
                id: 'newFolder',
                title: "新建目录",
                width: 520,
                height: 440,
                draggable: true,
                ajaxConfirm: true,

                url: url,
                initValue: {
                    isModify: false,
                    category: this.category,
                    parentGuid: currNode.id
                },
                returnValueFunctionName: 'confirmHandle',
                confirmCallback: this.saveNewFolder,
                cancelCallback: this.cancelNewFolder
            }
            this.$BiTopWin.$.bi.ui.frameDialog(options);
        },
        // 保存新建目录
        saveNewFolder: function (newNode) {
            let folderTree = this.$refs.folderTree;
            let parentNode = folderTree.getNode(newNode.parent);

            // 如果没有修改所属上级
            if (this.currentTreeNode.id === newNode.parent) {
                if (parentNode.loaded) {
                    parentNode.loaded = false;
                    parentNode.expand(() => {
                        folderTree.setCurrentKey(newNode.id);
                        this.setCurrentTreeNode();
                    });
                } else {
                    parentNode.expand(() => {
                        folderTree.setCurrentKey(newNode.id);
                        this.setCurrentTreeNode();
                    });
                }
            }
            // 如果修改了所属上级
            else {
                if (parentNode != null) {
                    if (parentNode.loaded) {
                        parentNode.loaded = false;
                        parentNode.expand(() => {
                            folderTree.setCurrentKey(newNode.id);
                            this.setCurrentTreeNode();
                        });
                    } else {
                        parentNode.expand(() => {
                            folderTree.setCurrentKey(newNode.id);
                            this.setCurrentTreeNode();
                        });
                    }
                } else {
                    // 如果父级没有被加载，通过路径递归加载父级
                    folderApi.getFolderNodePath({"fGuid": newNode.parent}).then((result) => {
                        if (result.length > 0) {
                            this.expandByPath(folderTree, newNode.id, result, 0);
                        }
                    })
                }
            }
        },
        // 取消新建保存目录
        cancelNewFolder: function () {

        },
        // 保存编辑目录
        saveModifyFolder: function (newNode) {
            if (newNode) {
                let folderTree = this.$refs.folderTree;
                this.currentTreeNode.label = newNode.label;
                this.currentTreeNode.code = newNode.code;
                let parentNode = folderTree.getNode(newNode.parent);

                // 如果修改了所属上级
                if (this.currentTreeNode.parent !== newNode.parent) {
                    // 先从现有目录下移除资源节点
                    folderTree.remove(this.currentTreeNode);

                    if (parentNode != null) {
                        if (parentNode.loaded) {
                            parentNode.loaded = false;
                            parentNode.expand(() => {
                                folderTree.setCurrentKey(newNode.id);
                                this.setCurrentTreeNode();
                            });
                        } else {
                            parentNode.expand(() => {
                                folderTree.setCurrentKey(newNode.id);
                                this.setCurrentTreeNode();
                            });
                        }
                    } else {
                        // 如果父级没有被加载，通过路径递归加载父级
                        folderApi.getFolderNodePath({"fGuid": newNode.parent}).then((result) => {
                            if (result.length > 0) {
                                this.expandByPath(folderTree, newNode.id, result, 0);
                            }
                        })
                    }
                }
            }
        },
        // 删除目录
        deleteFolder: function () {
            let currNode = this.$refs.folderTree.getCurrentNode();
            var params = {category: this.category, pId: currNode.id};

            folderApi.queryFolderTree(params).then((res) => {
                if (res.length > 0) {
                    let info = "如删除本目录，其下级数据目录及资源也将同步删除。继续删除请输入'OK'并点击确定：";
                    this.$BI.Dialog.warn(info, this.deleteFolderInsure, "确认删除", {ok: true, height: 230});
                } else {
                    this.$BI.Dialog.confirm("确认删除目录吗？", () => {
                        this.deleteFolderInsure();
                    });
                }
            });
        },
        // 确认删除目录
        deleteFolderInsure: function () {
            let currNode = this.$refs.folderTree.getCurrentNode();
            let datas = {"guid": currNode.id, "type": currNode.type}

            const loadingFolder = this.$loading({
                lock: true,
                text: '正在删除',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            folderApi.deleteFolderItem(datas).then((result) => {
                if (result.deleteSuccess === "true") {
                    loadingFolder.close();
                    this.$refs.folderTree.remove(currNode);
                    this.$refs.folderTree.setCurrentKey(currNode.parent);
                    this.setCurrentTreeNode();
                } else if (result.deleteSuccess === "false") {
                    loadingFolder.close();
                    // 元数据依赖项检测
                    top.$.bi.ui.error(result.msg, result.errorDetail);
                }
            }).catch((error) => {
                loadingFolder.close();
            });
        },
        // 刷新目录
        refreshFolder: function () {
            let folderTree = this.$refs.folderTree;
            let curNode = folderTree.getNode(this.currentTreeNode.id);

            if (curNode.loaded) {
                curNode.loaded = false;
                curNode.expand(() => {
                    folderTree.setCurrentKey(curNode.id);
                    this.setCurrentTreeNode();
                });
            } else {
                curNode.expand(() => {
                    folderTree.setCurrentKey(curNode.id);
                    this.setCurrentTreeNode();
                });
            }
        },
        // 新建数据资源
        newDres: function () {
            let url = this.$rootUrl + "/biDialog/dataResInfoRouter/newDataRes"
            let currNode = this.$refs.folderTree.getCurrentNode();
            let parentGuid = (currNode.type === this.$folderEnum.resource) ? currNode.parent : currNode.id;

            let options = {
                id: 'newDataRes',
                title: "新建数据资源",
                width: 660,
                height: 544,
                draggable: true,
                ajaxConfirm: true,

                url: url,
                initValue: {
                    parentGuid: parentGuid
                },
                returnValueFunctionName: 'confirmHandle',
                confirmCallback: this.saveNewDres,
                cancelCallback: this.cancelNewDres
            }
            this.$BiTopWin.$.bi.ui.frameDialog(options);
        },
        // 保存新建数据资源
        saveNewDres: function (newNode) {
            let folderTree = this.$refs.folderTree;
            let parentNode = folderTree.getNode(newNode.parent);

            if (parentNode.loaded) {
                parentNode.loaded = false;
                parentNode.expand(() => {
                    folderTree.setCurrentKey(newNode.id);
                    this.setCurrentTreeNode();
                });
            } else {
                parentNode.expand(() => {
                    folderTree.setCurrentKey(newNode.id);
                    this.setCurrentTreeNode();
                });
            }
        },
        // 取消新建数据资源
        cancelNewDres: function () {

        },
        // 删除数据资源
        deleteDres: function () {
            //启用发布，
            if (this.isPublished) {
                let currNode = this.$refs.folderTree.getCurrentNode();
                //是否启用发布审核流程
                ResAPI.getResPubState({resGuid: currNode.id, category: this.category}).then(result => {
                    //开启了工作流,状态是：已发布或者未发布--审批中时，不允许删除
                    if (result.wfswitched) {
                        let message = "";
                        if (result.published) {
                            message = "资源已发布，不能删除！";
                        }
                        if (result.examining && !result.published) {
                            message = "资源已申请发布，正在审批中，不能删除！";
                        }
                        if (message !== "") {
                            this.$BI.Dialog.warn(message);
                        } else {
                            this.doDeleteRes();
                        }

                    } else {
                        this.doDeleteRes();
                    }
                })

            } else {
                this.doDeleteRes();
            }
        },
        doDeleteRes() {
            this.$BI.Dialog.confirm('确认删除?', () => {
                let currNode = this.$refs.folderTree.getCurrentNode();
                dataresApi.deleteDataResource({"guid": currNode.id}).then((result) => {
                    if (result.deleteSuccess === "true") {
                        this.$refs.folderTree.remove(currNode);
                        this.$refs.folderTree.setCurrentKey(currNode.parent);
                        this.setCurrentTreeNode();
                    } else if (result.deleteSuccess === "false") {
                        // 元数据依赖项检测
                        top.$.bi.ui.error(result.msg, result.errorDetail);
                    }
                });
            })
        },
        // 保存编辑数据资源
        saveDataResource: function () {
            this.$nextTick(() => {
                this.$refs.baseinfo.saveBaseInfoItem((rstNode) => {
                    if (rstNode === false) {
                        this.mcCancel();
                        return;
                    }

                    // 如果是切换了页签
                    if (this.nextTabName != null) {
                        this.resetBaseTabTitle();
                        this.activeName = this.nextTabName;
                        this.nextTabName = null;
                        this.handleTabClick();
                    }
                    // 如果是切换了资源
                    else if (this.nextNodeData != null) {
                        this.resetBaseTabTitle();
                    }
                    // 如果是点击了保存
                    else {
                        this.resetBaseTabTitle();
                    }

                    // 修改当前节点
                    this.currentTreeNode.icon = rstNode.icon;
                    this.currentTreeNode.label = rstNode.label;
                    this.currentTreeNode.code = rstNode.code;
                    this.currentTreeNode.title = rstNode.label;
                    this.currentTreeNode.resType = rstNode.resType;
                    this.currentTreeNode.path = rstNode.path;

                    // 如果修改了所属目录
                    var folderTree = this.$refs.folderTree;
                    if (this.currentTreeNode.parent !== rstNode.parent) {
                        // 先从现有目录下移除资源节点
                        folderTree.remove(this.currentTreeNode);

                        // 展开新父级节点，如果已经展开则重新加载父级
                        let parentNode = folderTree.getNode(rstNode.parent);
                        if (parentNode != null) {
                            if (parentNode.loaded) {
                                parentNode.loaded = false;
                                parentNode.expand(() => {
                                    folderTree.setCurrentKey(rstNode.id);
                                    this.setCurrentTreeNode();

                                    if (this.nextNodeData != null) {
                                        this.$nextTick(() => {
                                            this.setCurrentTreeNode(this.nextNodeData);
                                            this.nextNodeData = null;
                                        });
                                    }
                                });
                            } else {
                                parentNode.expand(() => {
                                    folderTree.setCurrentKey(rstNode.id);
                                    this.setCurrentTreeNode();

                                    if (this.nextNodeData != null) {
                                        this.$nextTick(() => {
                                            this.setCurrentTreeNode(this.nextNodeData);
                                            this.nextNodeData = null;
                                        })
                                    }
                                });
                            }
                        } else {
                            // 如果父级没有被加载，通过路径递归加载父级
                            folderApi.getFolderNodePath({"fGuid": rstNode.parent}).then((result) => {
                                if (result.length > 0) {
                                    this.expandByPath(folderTree, this.currentTreeNode.id, result, 0);
                                }
                            })
                        }
                    } else {
                        if (this.nextNodeData != null) {
                            this.$nextTick(() => {
                                this.setCurrentTreeNode(this.nextNodeData);
                                this.nextNodeData = null;
                            });
                        }
                    }
                });
            });
        },
        formatDGuid: function (data) {
            var result = "";
            if (data.data) {
                result = data.data.dGuid ? data.data.dGuid : data.data.id;
            } else {
                result = data.dGuid ? data.dGuid : data.id;
            }
            return result;
        },
        // 设置当前选中树形节点
        setCurrentTreeNode: function (treeNode) {
            if (treeNode == null) {
                treeNode = this.$refs.folderTree.getCurrentNode();
            } else {
                if (this.isShowER && treeNode.isLeaf)
                    this.isShowER = false;
            }
            if (this.isShowER) {
                var curGuid = this.formatDGuid(this.currentTreeNode);
                var guid = this.formatDGuid(treeNode);
                if (curGuid !== guid) {
                    this.$nextTick(() => {
                        this.$refs.erView.outRefresh(guid);
                    });
                }
            }

            if (this.activeName === "baseInfo" && this.baseinfoModifyFlag) {
                this.$BI.Dialog.yesnocancel("基本属性内容已修改，是否保存？", this.mcConfirm, this.mcAbandon, this.mcCancel, "提示");
                this.nextNodeData = treeNode;
                this.$refs.folderTree.setCurrentKey(this.currentTreeNode.id);
                return;
            }
            if (this.activeName === "structure" && this.structModifyFlag) {
                this.$BI.Dialog.yesnocancel("数据结构内容已修改，是否保存？", this.mcConfirm, this.mcAbandon, this.mcCancel, "提示");
                this.nextNodeData = treeNode;
                this.$refs.folderTree.setCurrentKey(this.currentTreeNode.id);
                return;
            }

            if (this.applicationModified){
                this.$BI.Dialog.yesnocancel("当前应用系统已修改，是否保存？", this.mcConfirm, this.mcAbandon, this.mcCancel, "提示");
                this.nextNodeData = treeNode;
                this.$refs.folderTree.setCurrentKey(this.currentTreeNode.id);
                return;
            }
            if (this.folderModified){
                this.$BI.Dialog.yesnocancel("当前目录已修改，是否保存？", this.mcConfirm, this.mcAbandon, this.mcCancel, "提示");
                this.nextNodeData = treeNode;
                this.$refs.folderTree.setCurrentKey(this.currentTreeNode.id);
                return;
            }

            this.isShowRight = false;
            this.activeName = "baseInfo";
            this.currentTreeNode = treeNode;
            this.isNotShowDatastructTab = false;
            this.$refs.folderTree.setCurrentKey(this.currentTreeNode.id);
            if (this.currentTreeNode.type === this.$folderEnum.resource) {
                this.isShowRight = true;
                this.isNotShowDatastructTab = this.unstructFileResTypes.some((val, index, arr) => {
                    return val === this.currentTreeNode.resType;
                });
                this.handleTabClick();
            } else {
                let folderTreeNode = this.$refs.folderTree.getNode(this.currentTreeNode.id);
                if (folderTreeNode && !folderTreeNode.expanded) {
                    folderTreeNode.expand();
                }
            }
        },
        // 页签切换前处理
        tabBeforeLeave: function (nName, oName) {
            if (oName === "baseInfo" && this.baseinfoModifyFlag) {
                this.$BI.Dialog.yesnocancel("基本属性内容已修改，是否保存？", this.mcConfirm, this.mcAbandon, this.mcCancel, "提示");
                this.nextTabName = nName;
                return false;
            }
            if (oName === "structure" && this.structModifyFlag) {
                this.$BI.Dialog.yesnocancel("数据结构内容已修改，是否保存？", this.mcConfirm, this.mcAbandon, this.mcCancel, "提示");
                this.nextTabName = nName;
                return false;
            }
            return true;
        },
        // 页签点击处理
        handleTabClick: function () {
            let that = this;
            if (!this.baseinfoModifyFlag && !this.structModifyFlag) {
                if (this.activeName === "baseInfo") {
                    this.$nextTick(() => {
                        this.$refs.baseinfo.initPage();
                    });
                } else if (this.activeName === "structure") {
                    this.$nextTick(() => {
                        let currNode = this.$refs.folderTree.getCurrentNode();
                        this.$refs.structure.queryStructData(currNode.id, currNode.resType);
                    });
                } else if (this.activeName === "dataLink") {
                    this.$nextTick(() => {
                        let currNode = this.$refs.folderTree.getCurrentNode();
                        this.$refs.datalink.iniQueryDatas(currNode.id, that.isNotShowDatastructTab);
                    });
                }
            }
        },
        // 重置基本信息页签
        resetBaseTabTitle: function () {
            this.baseinfoModifyFlag = false;
            this.baseinfoTabTitle = "基本属性";
        },
        // 基本信息页签
        baseinfoModified: function () {
            this.baseinfoModifyFlag = true;
            this.baseinfoTabTitle = "基本属性";
        },
        // 重置数据结构页签修改标志
        resetStructTabTitle: function () {
            this.structModifyFlag = false;
        },
        // 数据结构页签修改标志
        structTabModified: function () {
            this.structModifyFlag = true;
        },
        // 保存提示-确定
        mcConfirm: function () {
            let that = this;
            // 如果是修改了基础信息
            if (this.baseinfoModifyFlag) {
                this.saveDataResource();
            }
            // 如果是修改了数据结构
            else if (this.structModifyFlag) {
                this.saveDataStruct();
            }
            // 如果是修改了应用系统
            else if(this.applicationModified){
                this.$nextTick(() => {
                    this.$refs.dataResApplicationModifyView.saveDomain().then((result) => {
                        if (result === false) {
                            that.mcCancel()
                        } else {
                            that.clearDirtyFlag();
                            that.setCurrentTreeNode(that.nextNodeData);
                            that.nextNodeData = null;
                        }
                    })
                })
            }
            // 如果是修改了目录
            else if (this.folderModified){
                this.$nextTick(() => {
                    this.$refs.dataResFolderModifyView.saveFolder().then((result) => {
                        if (result === false) {
                            that.mcCancel()
                        } else {
                            that.clearDirtyFlag();
                            that.setCurrentTreeNode(that.nextNodeData);
                            that.nextNodeData = null;
                        }
                    })
                })
            }
        },
        // 保存提示-放弃
        mcAbandon: function () {
            // 如果是修改了基础信息
            if (this.baseinfoModifyFlag) {
                // 如果页签切换
                if (this.nextTabName != null) {
                    this.activeName = this.nextTabName;
                    this.nextTabName = null;
                    this.resetBaseTabTitle();
                    this.handleTabClick();
                }
                // 如果资源切换
                if (this.nextNodeData != null) {
                    this.resetBaseTabTitle();
                    this.setCurrentTreeNode(this.nextNodeData);
                    this.nextNodeData = null;
                }
            }
            // 如果是修改了数据结构
            else if (this.structModifyFlag) {
                // 如果是切换了页签
                if (this.nextTabName != null) {
                    this.activeName = this.nextTabName;
                    this.nextTabName = null;
                    this.resetStructTabTitle();
                }

                // 如果是切换了资源
                if (this.nextNodeData != null) {
                    this.resetStructTabTitle();
                    this.setCurrentTreeNode(this.nextNodeData);
                    this.nextNodeData = null;
                }
            }else if (this.applicationModified || this.folderModified){
                if (this.nextNodeData.id === this.currentTreeNode.id){

                    this.applicationModified ?
                        this.$refs.dataResApplicationModifyView.initModifyFolderItem(this.currentTreeNode.id)
                        :
                        this.$refs.dataResFolderModifyView.initModifyFolderItem(this.currentTreeNode.id, this.currentTreeNode.parent)

                    this.clearDirtyFlag();
                } else{
                    this.clearDirtyFlag();
                    this.setCurrentTreeNode(this.nextNodeData);
                }


                this.nextNodeData = null;
            }
        },
        // 保存提示-取消
        mcCancel: function () {
            this.nextTabName = null;
            this.nextNodeData = null;
        },
        // 保存数据结构
        saveDataStruct: function () {
            this.$nextTick(() => {
                this.$refs.structure.saveStructureBatch((result) => {
                    if (result === false) {
                        this.mcCancel();
                        return;
                    }

                    // 如果是切换了页签
                    if (this.nextTabName != null) {
                        this.resetStructTabTitle();
                        this.activeName = this.nextTabName;
                        this.nextTabName = null;
                    }
                    // 如果是切换了资源
                    else if (this.nextNodeData != null) {
                        this.resetStructTabTitle();
                        this.setCurrentTreeNode(this.nextNodeData);
                        this.nextNodeData = null;
                    }
                    // 如果是点击了保存
                    else {
                        this.resetStructTabTitle();
                    }
                });
            });
        },
        // 递归加载父级
        expandByPath: function (tree, guid, paths, i) {
            var pNode = tree.getNode(paths[i]);
            if (pNode == null) {
                return;
            }

            pNode.expand(() => {
                if (tree.getNode(guid) != null) {
                    tree.setCurrentKey(guid);
                    this.setCurrentTreeNode();
                } else {
                    this.expandByPath(tree, guid, paths, ++i);
                }
            })
        },
        // 发布资源
        publishRes: function () {
            this.publishType = "true";
            this.publishDialogTitle = "发布资源";
            let url = this.$rootUrl + "/biDialog/resPublishRouter/publishRes"

            let options = {
                id: 'publishRes',
                title: "发布资源",
                width: 800,
                height: 480,
                showMax: true,
                draggable: true,
                resizable: true,
                ajaxConfirm: true,

                url: url,
                initValue: {
                    category: this.category,
                    publishType: this.publishType,
                    currTreeNode: this.currentTreeNode
                },
                returnValueFunctionName: 'confirmHandle',
                confirmCallback: this.savePublishRes
            }
            this.$BiTopWin.$.bi.ui.frameDialog(options);
        },
        // 取消发布
        revokePublishRes: function () {
            this.publishType = "false";
            this.publishDialogTitle = "取消发布";
            let url = this.$rootUrl + "/biDialog/resPublishRouter/revokePublishRes"

            let options = {
                id: 'revokePublishRes',
                title: "取消发布",
                width: 800,
                height: 480,
                showMax: true,
                draggable: true,
                resizable: true,
                ajaxConfirm: true,

                url: url,
                initValue: {
                    category: this.category,
                    publishType: this.publishType,
                    currTreeNode: this.currentTreeNode
                },
                returnValueFunctionName: 'confirmHandle',
                confirmCallback: this.savePublishRes
            }
            this.$BiTopWin.$.bi.ui.frameDialog(options);
        },
        // 保存发布/撤销资源
        savePublishRes: function (res) {
            if (res.data.isWFOpen === true) {
                if (this.publishType === "true") {
                    this.$BI.Dialog.success(res.data.message);
                } else {
                    this.$BI.Dialog.success(res.data.message);
                }
            } else {
                if (this.publishType === "true") {
                    this.$BI.Dialog.msg(res.data.message, {type: "success"});
                } else {
                    this.$BI.Dialog.msg(res.data.message, {type: "success"});
                }
            }

            this.publishDialogTitle = "";
            this.$nextTick(() => {
                this.checkJudge();
            })
        },
        async checkJudge() {
            let nodeId = (this.currentTreeNode === null) ? "" : this.currentTreeNode.id;
            let resAuth = await dataresApi.judgeModify({"category": this.category, "nodeId": nodeId});
            this.resModifyAuth = resAuth.canModify; // 用户在权限体系中是否具有修改权限
            this.canModify = resAuth.canModify;

            // 如果当前选中的是资源节点，且用户在权限体系中具有修改权限
            if (this.resModifyAuth && ((this.currentTreeNode != null)) && (this.currentTreeNode.type === this.$folderEnum.resource)) {
                // 如果开启了启用发布系统选项
                let resPubState = await ResAPI.getResPubState({resGuid: nodeId, category: this.category});
                this.publishEnable = resPubState.enablePub;
                if (resPubState.enablePub) {
                    // 资源已发布，发布按钮置灰；取消发布不置灰
                    if (resPubState.published) {
                        this.canModify = false;
                        this.publishDisabled = true;
                        this.publishReverseDisabled = false;
                    } else {
                        this.canModify = true;
                        this.publishDisabled = false;
                        this.publishReverseDisabled = true;
                    }
                }

                // 开启了工作流,状态是：已发布或者未发布--审批中时，不允许删除
                if (resPubState.wfswitched) {
                    // 资源已经发布
                    if (resPubState.published) {
                        // 资源取消发布审批中，发布按钮置灰，取消发布按钮显示为取消发布中，按钮置灰
                        if (resPubState.examining) {
                            this.canModify = false;
                            this.publishDisabled = true;
                            this.publishReverseDisabled = true;

                            this.publishBtnTitle = "发布";
                            this.publishReverseBtnTitle = "取消发布中";
                        } else {
                            this.canModify = false;
                            this.publishDisabled = true;
                            this.publishReverseDisabled = false;

                            this.publishBtnTitle = "发布";
                            this.publishReverseBtnTitle = "取消发布";
                        }
                    } else {
                        // 资源发布审批中，发布按钮显示为发布中，置灰，取消发布按钮也置灰；
                        if (resPubState.examining) {
                            this.canModify = false;
                            this.publishDisabled = true;
                            this.publishReverseDisabled = true;

                            this.publishBtnTitle = "发布中";
                            this.publishReverseBtnTitle = "取消发布";
                        } else {
                            this.canModify = true;
                            this.publishDisabled = false;
                            this.publishReverseDisabled = true;

                            this.publishBtnTitle = "发布";
                            this.publishReverseBtnTitle = "取消发布";
                        }
                    }
                }
            }
        },
        // 辅助功能-生成资源报告
        generateResReport: function () {
            let that = this;
            let url = this.$rootUrl + "/biDialog/generateResReportRouter/generateResReport";

            let options = {
                id: 'generateResReport',
                title: "生成资源报告",
                url: url,
                width: 1100,
                minWidth: 1100,
                height: 700,
                minHeight: 700,
                draggable: true,
                showMax: true,
                resizable: true,
                buttons: [{
                    id: "irp-exp-word", text: "导出WORD", async: true, click: function (btn, handler) {
                        var frame = this.find('iframe[biFrameDialog=true]')[0];
                        var returnFunction = frame.contentWindow['createResReport'];

                        if ($.isFunction(returnFunction)) {
                            if ($.isFunction(handler)) {
                                returnFunction(function (result) {
                                    if (result === false) {
                                        handler(false);
                                        return;
                                    }
                                    handler(that.doResExportCheck('word', result));
                                });
                            }
                        }
                    }
                }, {
                    id: "irp-exp-pdf", text: "导出PDF", async: true, click: function (btn, handler) {
                        var frame = this.find('iframe[biFrameDialog=true]')[0];
                        var returnFunction = frame.contentWindow['createResReport'];

                        if ($.isFunction(returnFunction)) {
                            if ($.isFunction(handler)) {
                                returnFunction(function (result) {
                                    if (result === false) {
                                        handler(false);
                                        return;
                                    }
                                    handler(that.doResExportCheck('pdf', result));
                                });
                            }
                        }
                    }
                }]
            }
            this.$BiTopWin.$.bi.ui.frameDialog(options);
        },
        // 生成资源报告-调用即时任务导出资源报告
        doResExportCheck: function (fileType, resList) {
            var realtimeJob = new RealtimeJob(this.$ContextPath);
            realtimeJob.exec({
                group: "irp_generateResReport", // 此处为即时任务的group
                jobTitle: "生成资源报告",  // 此次任务的标题
                params: {
                    windowType: "DataResFrame", // 打开窗口为数据资源
                    fileType: fileType,   // 导出文件类型
                    resList: resList,     // 勾选资源列表
                    localColProps: window.localStorage.getItem("IRP_DB_COLUMNS")    // 列选择数据（信息资源数据结构使用）
                },
                linkSources: ["irp.export"],    // 任务唯一标识（控制独占导出）
                successCallback: function () {
                },
                failCallback: function () {
                },
                backAble: true,
                cancelAble: true,
            });
            realtimeJob = null;
        },
        // 辅助功能-更新索引
        updateIndexAll: function () {
            this.$refs.updateIndexView.updateIndex(this.$categoryEnum.dataRes);
        },
        // 辅助功能-自动编目
        modifyAutoEdit: function () {
            let url = this.$rootUrl + "/ds/dialog/autoEditView/ds-irp-aytoedit";
            let options = {
                id: 'ds-irp-aytoedit',
                title: "自动编目",
                width: 422,
                minWidth: 422,
                height: 244,
                minHeight: 244,
                // draggable: true,
                ajaxConfirm: true,
                // showMax: true,
                // resizable: true,

                url: url,
                initValue: {
                    categoryType: this.category,
                },
                returnValueFunctionName: 'confirmHandle',
                confirmCallback: this.openAutoProgressDialog,
                cancelCallback: this.cancelCallbackAutoEdit,
                close: this.cancelCallbackAutoEdit
            }
            this.$BiTopWin.$.bi.ui.frameDialog(options);
        },

        cancelCallbackAutoEdit: function () {
            this.$BiTopWin.document.getElementById("bsp_topPanel_dimension").style.display = "none";
            this.$BiTopWin.document.getElementById("bsp_topPanel_autofolderSelect").style.display = "none";
        },

        openAutoProgressDialog: function (nodeData) {
            this.$BiTopWin.$.bi.ui.closeDialog("irp-aytoedit", window);
            let url = this.$rootUrl + "/ds/dialog/autoCataProgress/ds-autoCataProgress";
            let options = {
                id: 'ds-autoCataProgress',
                title: "自动编目",
                width: 800,
                minWidth: 800,
                height: 200,
                draggable: true,
                ajaxConfirm: true,

                url: url,
                initValue: {
                    categoryType: this.category,
                    nodeData: nodeData
                },
                returnValueFunctionName: 'confirmHandle',
                confirmCallback: this.saveModifyAutoEdit
            }
            this.$BiTopWin.$.bi.ui.frameDialog(options);
        },
        // 辅助功能-保存自动编目
        saveModifyAutoEdit: function (result) {
            this.$BiTopWin.$.bi.ui.closeDialog('autoCataProgress', window);
            this.sureAutoCilck(result.successNum, result.defeatedNum, result.resultLevel, result.nodeData);
        },

        sureAutoCilck: function (successNum, defeatedNum, resultLevel, newNode) {
            successNum = successNum === undefined ? 0 : successNum;
            defeatedNum = defeatedNum === undefined ? 0 : defeatedNum;
            resultLevel = resultLevel === undefined ? 0 : resultLevel;
            let defouatMes = defeatedNum > 0 ? ("\n重复编目：" + defeatedNum) + "个" : "";
            this.$BI.Dialog.alert("增加目录：" + resultLevel + "级\n" + "共增加末级目录：" + successNum + "个" + defouatMes, () => {
                this.refreshNewFolder(newNode);
            }, '提示');

        },

        // 自动编目完成后左侧树形刷新
        refreshNewFolder: function (newNode) {
            let folderTree = this.$refs.folderTree;
            let curNode = folderTree.getNode(newNode.id);
            // 如果修改了所属上级
            if (newNode.parent == null || newNode.parent === "") {
                curNode.expand(() => {
                    folderTree.setCurrentKey(curNode.id);
                    this.setCurrentTreeNode();
                });
            } else {
                // 如果父级没有被加载，通过路径递归加载父级
                folderApi.getFolderNodePath({"fGuid": newNode.parent}).then((result) => {
                    if (result.length > 0) {
                        this.expandByPathAll(folderTree, newNode.id, result, 0);
                    }
                })
            }
            this.refreshFolderGdnode(newNode.id);
        },
        // 递归加载父级
        expandByPathAll: function (tree, guid, paths, i) {
            var pNode = tree.getNode(paths[i]);
            if (pNode == null) {
                return;
            }
            pNode.expand(() => {
                if (tree.getNode(guid) != null) {
                    tree.setCurrentKey(guid);
                    this.setCurrentTreeNode();
                } else {
                    this.expandByPathAll(tree, guid, paths, ++i);
                }
            })
        },
        // 刷新目录
        refreshFolderGdnode: function (curNodeid) {
            let folderTree = this.$refs.folderTree;
            let curNode = folderTree.getNode(curNodeid);
            if (!curNode) {
                return;
            }
            if (curNode.loaded) {
                curNode.loaded = false;
                curNode.expand(() => {
                    folderTree.setCurrentKey(curNode.id);
                    this.setCurrentTreeNode();
                });
            } else {
                curNode.expand(() => {
                    folderTree.setCurrentKey(curNode.id);
                    this.setCurrentTreeNode();
                });
            }
        },
        // 辅助功能-从二维表导入资源
        addiresByTableFunc: function () {
            let currNode = this.$refs.folderTree.getCurrentNode();
            let folderNode = currNode;
            if (folderNode.isLeaf) {
                folderNode = this.$refs.folderTree.getNode(folderNode.parent).data;
            }

            let url = this.$rootUrl + "/ds/dialog/addresByTable/ds-addresByTable";
            let options = {
                id: 'ds-addresByTable',
                title: "从数据库导入",
                width: 1000,
                minWidth: 1000,
                height: 710,
                minHeight: 710,
                draggable: true,
                ajaxConfirm: true,
                showMax: true,
                resizable: true,

                url: url,
                initValue: {
                    categoryType: this.category,
                    currNode: currNode.isLeaf ? currNode.parent : currNode.id,
                    folderNode: folderNode
                },
                returnValueFunctionName: 'confirmHandle',
                confirmCallback: this.addiresByTable,
            }
            this.$BiTopWin.$.bi.ui.frameDialog(options);
        },

        // 辅助功能-生成资源
        addiresByTable: function (newNode) {
            let folderTree = this.$refs.folderTree;
            let parentNode = folderTree.getNode(newNode.parent);

            // 如果没有修改所属上级
            if (this.currentTreeNode.id === newNode.parent) {
                if (parentNode.loaded) {
                    parentNode.loaded = false;
                    parentNode.expand(() => {
                        folderTree.setCurrentKey(newNode.id);
                        this.setCurrentTreeNode();
                    });
                } else {
                    parentNode.expand(() => {
                        folderTree.setCurrentKey(newNode.id);
                        this.setCurrentTreeNode();
                    });
                }
            } else { // 如果修改了所属上级
                if (parentNode != null) {
                    if (parentNode.loaded) {
                        parentNode.loaded = false;
                        parentNode.expand(() => {
                            folderTree.setCurrentKey(newNode.id);
                            this.setCurrentTreeNode();
                        });
                        folderApi.getFolderNodePath({fGuid: newNode.parent}).then(result => {
                            if (result.length > 0) {
                                this.expandByPath(folderTree, newNode.id, result, 0);
                            }
                        });
                    } else {
                        parentNode.expand(() => {
                            folderTree.setCurrentKey(newNode.id);
                            this.setCurrentTreeNode();
                        });
                    }
                } else {
                    // 如果父级没有被加载，通过路径递归加载父级
                    folderApi.getFolderNodePath({fGuid: newNode.parent}).then(result => {
                        if (result.length > 0) {
                            this.expandByPath(folderTree, newNode.id, result, 0);
                        }
                    });
                }
            }
        },
        // 辅助功能-从文件导入库表资源
        powerDisgnerFunc: function () {
          let currNode = this.$refs.folderTree.getCurrentNode();
          let folderNode = currNode;
          if (folderNode.isLeaf) {
              folderNode = this.$refs.folderTree.getNode(folderNode.parent).data;
          }
            let url = this.$rootUrl + "/ds/dialog/powerDisgner/ds-powerFrom";
            let options = {
                id: 'ds-powerFrom',
                title: "从Power Designer模型导入",
                width: 960,
                minWidth: 960,
                height: 554,
                minHeight: 554,
                draggable: true,
                ajaxConfirm: true,
                showMax: true,
                resizable: true,

                url: url,
                initValue: {
                  categoryType: this.category,
                  currNode: currNode.isLeaf ? currNode.parent : currNode.id,
                  folderNode: folderNode
                },
                returnValueFunctionName: 'confirmHandle',
                confirmCallback: this.tableSure
            }
            this.$BiTopWin.$.bi.ui.frameDialog(options);
        },
        // 辅助功能-从文件导入库表资源 --确认
        tableSure: function (node) {
            this.refreshNewFolderPowerDesigner(node);
        },
        // 辅助功能-刷新从PD文件导入资源
        refreshNewFolderPowerDesigner: function (newNode) {
            let folderTree = this.$refs.folderTree;
            let parentNode = folderTree.getNode(newNode.parent);
            // 如果没有修改所属上级
            if (this.currentTreeNode.id === newNode.parent) {
                if (parentNode.loaded) {
                    parentNode.loaded = false;
                    parentNode.expand(() => {
                        folderTree.setCurrentKey(newNode.id);
                        this.setCurrentTreeNode(this.$refs.folderTree.getNode(newNode.id).data);
                    });
                } else {
                    parentNode.expand(() => {
                        folderTree.setCurrentKey(newNode.id);
                        this.setCurrentTreeNode(this.$refs.folderTree.getNode(newNode.id).data);
                    });
                }
            } else { // 如果修改了所属上级
                if (parentNode != null) {
                    if (parentNode.loaded) {
                        parentNode.loaded = false;
                        parentNode.expand(() => {
                            folderTree.setCurrentKey(newNode.id);
                            //this.onTreeNodeClick();
                            this.setCurrentTreeNode(this.$refs.folderTree.getNode(newNode.id).data);
                        });
                        folderApi.getFolderNodePath({fGuid: newNode.parent}).then(result => {
                            if (result.length > 0) {
                                this.expandByPath(folderTree, newNode.id, result, 0);
                            }
                        });
                    } else {
                        parentNode.expand(() => {
                            folderTree.setCurrentKey(newNode.id);
                            this.setCurrentTreeNode(this.$refs.folderTree.getNode(newNode.id).data);
                        });
                    }
                } else {
                    // 如果父级没有被加载，通过路径递归加载父级
                    folderApi.getFolderNodePath({fGuid: newNode.parent}).then(result => {
                        if (result.length > 0) {
                            this.expandByPath(folderTree, newNode.id, result, 0);
                        }
                    });
                }
            }
        },
        // 辅助功能-ER图管理
        erManage: function () {
            this.isShowER = true;
        },
        clickERNode: function (data) {
            var params = {category: this.category, pId: data.dimTreeNames[0]};
            folderApi.queryFolderTree(params).then((res) => {
                for (var i = 0; i < res.length; i++) {
                    if (res[i].id === data.guid) {
                        this.refreshNewFolder(res[i]);
                        break;
                    }
                }
            })
        },
        quitER: function () {
            this.isShowER = false;
            this.handleTabClick();
        },
        // 上移目录
        moveUp: function () {
            //得到当前节点
            let node = this.$refs.folderTree.getCurrentNode();

            if (node == null) {
                return false;
            }
            //获取当前节点的父级下所有子节点
            let pchildNodes = this.$refs.folderTree.getNode(node.id).parent.childNodes;
            let index = 0;
            for (let i = 0; i < pchildNodes.length; i++) {
                if (pchildNodes[i].data.id === node.id) {
                    index = i;
                }
            }
            if (index === 0) {
                this.$message({message: '处于顶端，不能继续上移', type: 'warning'});
                return false;
            }
            if (node.type !== pchildNodes[index - 1].data.type) {
                return false;
            }
            let folders = [];
            let folderItem = {"guid": node.id, "lable": node.label, "order": pchildNodes[index - 1].data.order};
            folders.push(folderItem);
            let folderItem2 = {
                "guid": pchildNodes[index - 1].data.id,
                "lable": pchildNodes[index - 1].data.label,
                "order": node.order
            };
            folders.push(folderItem2);
            if (pchildNodes[index - 1].data.order === node.order) {
                return false;
            }
            let datas = {datas: JSON.stringify(folders)};
            this.crurentNodeShow(node, datas, pchildNodes, index, "up");
        },
        // 下移目录
        moveDown: function () {
            //得到当前节点
            let node = this.$refs.folderTree.getCurrentNode();
            if (node == null) {
                return false;
            }
            //获取当前节点的父级下所有子节点
            let pchildNodes = this.$refs.folderTree.getNode(node.id).parent.childNodes;
            let index = 0;
            for (let i = 0; i < pchildNodes.length; i++) {
                if (pchildNodes[i].data.id === node.id) {
                    index = i;
                }
            }
            if (index === (pchildNodes.length - 1)) {
                this.$message({message: '处于底端，不能继续下移', type: 'warning'});
                return false;
            }
            if (node.type !== pchildNodes[index + 1].data.type) {
                return false;
            }
            let folders = [];
            let folderItem = {"guid": node.id, "lable": node.label, "order": pchildNodes[index + 1].data.order};
            folders.push(folderItem);
            let folderItem2 = {
                "guid": pchildNodes[index + 1].data.id,
                "lable": pchildNodes[index + 1].data.label,
                "order": node.order
            };
            folders.push(folderItem2);
            if (pchildNodes[index + 1].data.order === node.order) {
                return false;
            }
            let datas = {datas: JSON.stringify(folders)};
            this.crurentNodeShow(node, datas, pchildNodes, index, "down");
        },
        moveNode: function (data, crunode, nextnode, movetype, index) {
            if (movetype === 'up') {
                this.$refs.folderTree.getNode(data.id).parent.insertBefore(crunode, nextnode);
                index = index + 1;
            } else {
                this.$refs.folderTree.getNode(data.id).parent.insertAfter(crunode, nextnode);
            }
            this.$refs.folderTree.getNode(data.id).parent.childNodes.splice(index, 1);
        },
        crurentNodeShow: function (node, datas, pchildNodes, index, movetype) {
            let type = node.type;
            let nextNode;
            if (movetype === 'up') {
                nextNode = pchildNodes[index - 1];
            } else {
                nextNode = pchildNodes[index + 1];
            }
            let order = nextNode.data.order;
            this.$refs.folderTree.getNode(nextNode.data.id).data.order = node.order;
            node.order = order;

            if (type === '04') {
                dataresApi.updateBaseOrderBatch(datas).then(result => {
                    this.moveNode(node, pchildNodes[index], nextNode, movetype, index);
                });
            } else {
                folderApi.updateFolderOrder(datas).then(result => {
                    this.moveNode(node, pchildNodes[index], nextNode, movetype, index);
                });
            }
            const secounds = 1
            let num = 0
            const timer = setInterval(() => {
                if (num < secounds) {
                    num++
                } else {
                    clearInterval(timer)
                    this.$refs.folderTree.setCurrentKey(node.id);
                    // this.setCurrentTreeNode(this.$refs.folderTree.getNode(node.id).data);
                }
            }, 200);
        },
        doConformCheck() {
            inforesApi.conformCheck({resGuid: this.currentTreeNode.id}).then(res => {
                let url = this.$rootUrl + "/biDialog/res/conformcheck/resConformCheck";
                let initValue = {
                    conformResult: res,
                    resGuid: this.currentTreeNode.id
                }
                let options = {
                    id: "resConformCheck",
                    title: "检测结果",
                    draggable: true,
                    url: url,
                    initValue: initValue,
                    onlyCloseBtn: true,
                    width: 960,
                    height: 710
                }
                this.$BiTopWin.$.bi.ui.frameDialog(options);
            })
        },
        doBatchConformCheck() {
            this.$BI.Dialog.confirm('是否对所有资源进行元数据符合性检测？', () => {
                var realtimeJob = new RealtimeJob(this.$ContextPath);
                realtimeJob.exec({
                    group: "irp_conformcheck", //此处为即时任务的group
                    jobTitle: "资源元数据符合性检测",  //此次任务的标题
                    params: {
                        category: this.category
                    },
                    successCallback: function () {
                    },
                    failCallback: function () {
                    }
                });
                realtimeJob = null;
            });
        },
        checkIsAdmin() {
            ResAPI.isAdmin().then(res => {
                this.isAdmin = res.isAdmin;
            })
        },
        resBloodMap: function () {
            let guid = this.currentTreeNode.id

            let url = this.$frontContextPath + "/metagraph-app/dist/index.html#/metagraph/index?guid=" + guid + "&type=1";
            $.bi.getRootWindow().nros.getPlugin('event').emit('open-page', {appName: 'metagraph-app', iframeUrl: url})
            // this.openPage(url)
        },
        openPage: function (url) {
            if (!this.$('#_tmpproxy').length) {
                var proxy = this.$("<a href='about:blank' id='_tmpproxy' style='visibility: hidden;' target='_blank'><span id='_tmpproxyText'>&nbsp;</span></a>");
                this.$('body').append(proxy);
            }
            var proxyElem = document.getElementById('_tmpproxy');
            proxyElem.href = url;
            var proxyText = document.getElementById('_tmpproxyText');
            proxyText.click();
        },
        resAffectMap: function () {
            let guid = this.currentTreeNode.id
            let url = this.$frontContextPath + "/metagraph-app/dist/index.html#/metagraph/index?guid=" + guid + "&type=2";
            $.bi.getRootWindow().nros.getPlugin('event').emit('open-page', {appName: 'metagraph-app', iframeUrl: url})
            //this.openPage(url)
        },
        getMetaGraphOptions: function () {
            metaGraphApi.getSysOptions().then(res => {
                this.isOpenMetaGraph = res && res.isOpenGraph
            })
        },
        initWorkSpaces: function () {
            BiCommonApi.getWorkSpaces('IRP_DR_TYPE').then(res => this.workSpaces = res).catch(() => {
                // 忽略
            })
        },
        compareWorkTitle: function (applicationTitle) {
            for (let i = 0; i < this.workSpaces.length; i++) {
                let workSpace = this.workSpaces[i]
                if (workSpace.workSpaceTitle === applicationTitle) {
                    return true
                }
            }
            return false
        },
        applicationModifyCallback: function (modified) {
            this.applicationModified = modified
        },
        folderModifyCallback: function (modified) {
            this.folderModified = modified
        }
    },
    created() {
        this.doLocateFirstDomain = true
        this.initTreeNodeSeparator()
        this.initWorkSpaces()
    },
    mounted() {
        this.getMetaGraphOptions()
        this.checkJudge();
        this.checkIsAdmin();
        let _this = this;
        // 嵌入BI后，页面编辑后，提示保存
        this.initPageModifyListener();
        try {
            this.initLocationListener();
        }catch (e) {
            console.log(e)
        }
        // 查询全部非结构化文件资源类型
        this.queryAllUnstructFileResTypes();
        // 查询是否开启发布
        dataresApi.queryIsPublish().then((result) => {
            this.isPublished = result.isPublish;
        });
        dataresApi.queryIsOrder().then((result) => {
            this.isShowMove = result.isOrder;
        });
        // BI左侧菜单切换-是否脏数据
        window["isDirty"] = () => {
            return this.isChange
        }
        // BI左侧菜单切换-否回调方法
        window["saveRollbackAsync"] = (callback) => {
            _this.clearDirtyFlag();
            callback(true);
        }
        // BI左侧菜单切换-确认回调方法
        window["confirmAsync"] = (callback) => {
            if (_this.baseinfoModifyFlag) {
                _this.$nextTick(() => {
                    _this.$refs.baseinfo.saveBaseInfoItem((rstNode) => {
                        if (rstNode === false) {
                            callback(false);
                        } else {
                            _this.clearDirtyFlag();
                            callback(true);
                        }
                    });
                });
            } else if (_this.structModifyFlag) {
                _this.$nextTick(() => {
                    _this.$refs.structure.saveStructureBatch((result) => {
                        if (result === false) {
                            callback(false);
                        } else {
                            _this.clearDirtyFlag();
                            callback(true);
                        }
                    });
                });
            } else if (_this.applicationModified) {
                _this.$nextTick(() => {
                    _this.$refs.dataResApplicationModifyView.saveDomain().then((result) => {
                        if (result === false) {
                            callback(false);
                        } else {
                            _this.clearDirtyFlag();
                            callback(true);
                        }
                    });
                });
            } else if (_this.folderModified) {
                _this.$nextTick(() => {
                    _this.$refs.dataResFolderModifyView.saveFolder().then((result) => {
                        if (result === false) {
                            callback(false);
                        } else {
                            _this.clearDirtyFlag();
                            callback(true);
                        }
                    });
                });
            }
        }

    }
}
</script>

<style scoped>
/* 页面最大宽度 */
#dres-container {
    min-width: 1430px;
}

/* 左侧内容 - 顶部内间距 */
.bi-layout-left {
    padding-top: 2px;
}

/* 右侧内容 - 顶部内间距 */
.bi-layout-right {
    padding: 16px;
    box-shadow: 0 0 4px 0 #e0e2e3;
}

/* 顶部工具栏 - 边框阴影及圆角 */
.bi-toolbar {
    border-radius: 0px 0px 0px 2px;
    box-shadow: 0px 0px 4px 0px #E0E2E3;
}

/* 保存强调按钮 */
.tab-btns {
    position: absolute;
    z-index: 999;
    right: 12px;
}
</style>
